﻿using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using UnityEngine;

[XmlRoot("level")]
public class Level {
	

	[XmlArray("nodelist"),XmlArrayItem("node")]
	public List<Node> nodes = new List<Node> ();

	public static Level ReadLevel(string file)
	{
		XmlSerializer serializer = new XmlSerializer(typeof(Level));
		TextAsset xml = Resources.Load (file) as TextAsset;

		if (xml != null) 
		{
			using (var reader = new System.IO.StringReader(xml.text))
			{
				return serializer.Deserialize(reader) as Level;
			}
		} 
		else
		{
			Debug.Log("invalid resource:" + file);
			return null;
		}
	}

}
